angular
    .module("Ajani.filters", [])
    .filter("truncate", () ->
        truncate = (text, length, end) ->
            truncated = ""
            if isNaN(length)
                length = 100
            if end is undefined
                end = "..."
            if text.length <= length || text.length - end.length <= length
                truncated = text
            else
                truncated = String(text).substring(0, length-end.length) + end
            truncated
    )
    .filter("formatsize", ["$filter", ($filter)->
        formatsize = (size) ->
            kb = size/1024
            $filter('number')(kb, 2)
    ])